﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using EnergyConsumptionMonitorSystem.Components;
using EnergyConsumptionMonitorSystem.Models;

namespace EnergyConsumptionMonitorSystem.MainWindowTabItem
{
    /// <summary>
    /// Interaction logic for LogInUC.xaml
    /// </summary>
    public partial class LogInUC : UserControl, ITabItemContentUC
    {
        public event EventHandler RegisterEvent;

        private MainWindowTabItem _container;
        public MainWindowTabItem Container
        {
            get
            {
                return this._container;
            }
            set
            {
                if (this._container != value)
                {
                    if (this._container != null)
                    {
                        this._container.ClosingEvent -= this.tabItem_ClosingEvent;
                    }
                    this._container = value;
                    value.ClosingEvent += new System.ComponentModel.CancelEventHandler(tabItem_ClosingEvent);
                }
            }
        }

        public LogInUC()
        {
            InitializeComponent();
        }

        public LogInUC(MainWindowTabItem tabItem)
            : this()
        {
            this.Container = tabItem;
        }

        private void tabItem_ClosingEvent(object sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = true;
        }

        private void btnLogIn_Click(object sender, RoutedEventArgs e)
        {
            if (txtUserName.Text == "sa" && txtPassword.Password == "password")
            {
                Singleton<LogInStatus>.Instance.UserName = "sa";
                Singleton<LogInStatus>.Instance.Status = true;             
            }
        }

        private void btnRegister_Click(object sender, RoutedEventArgs e)
        {
            if (this.RegisterEvent != null)
            {
                this.RegisterEvent(this,new EventArgs());
            }
        }

        public event EventHandler CloseRequestEvent;
    }
}
